import Mock from 'mockjs'
import it from "element-ui/src/locale/lang/it";
import { Message } from "element-ui";
// 用户信息
const users = [
    {
        id: 1,
        username: 'student',
        password: '123456',
        token: 'student-token',
        role: 'student',
        rights: []
    },
    {
        id: 2,
        username: 'admin',
        password: '123456',
        token: 'admin-token',
        role: 'admin',
        rights: []
    }
]
const roles = {
    student: [
        {
            id: 1,
            authName: '商品',
            icon: 'el-icon-connection',
            children: [
                {
                    id: 11,
                    authName: '分类',
                    icon: 'el-icon-s-grid',
                    path: 'category',
                    rights: ['view']
                },
                {
                    id: 12,
                    authName: '热卖',
                    icon: 'el-icon-s-marketing',
                    path: 'bestSell',
                    rights: ['view', 'edit', 'add', 'delete']
                }
            ]
        }
    ],
    admin: [
        {
            id: 1,
            authName: '商品',
            icon: 'el-icon-connection',
            children: [
                {
                    id: 11,
                    authName: '分类',
                    icon: 'el-icon-s-grid',
                    path: 'category',
                    rights: ['view']
                },
                {
                    id: 12,
                    authName: '热卖',
                    icon: 'el-icon-s-marketing',
                    path: 'bestSell',
                    rights: ['view', 'edit']
                }
            ]
        },
        {
            id: 2,
            authName: '用户权限',
            icon: 'el-icon-set-up',
            children: [
                {
                    id: 21,
                    authName: '管理员',
                    icon: 'el-icon-s-custom',
                    path: 'admin',
                    rights: ['view', 'edit']
                }
            ]
        }
    ]
}
// 表格数据
const dataList = Mock.mock({
    "data|5": [
        {
            "shopId|+1": 1, //生成id，自增1
            "shopName": "@cname", //生成姓名(这里生成的是中文名称)
            "shopImg": "@Image('100*40','#c33','#ffffff','商品')", //生成随机图片(大小/背景色/字体颜色/文字信息),打印的是图片地址
            "shopVolume|30-1000": 30, //随机生成30至1000的数字(价格)
            "shopAddress": "@county(true)", //随机生成地址
            "shopDate": "@date('yyyy-MM-dd')", //随机生成yyyy-MM-dd格式的日期
            "shopPhone": /^1(5|3|7|8)[0-9]{9}$/, //随机生成电话号码
            "shopStart|1-5": "★", //随机生成1至5个指定的图形(★)
        }
    ]
})
Mock.mock(/\/login/, 'post', option => {
    const { password, username } = JSON.parse(option.body)
    for (let i = 0; i < users.length; i++) {
        if (password === users[i].password && username === users[i].username) {
            return {
                meta: {
                    msg: '登录成功',
                    code: 200,
                    token: 'Bearer asd1'
                },
                users: users[i]
            }

        }
    }
    return {
        meta: {
            msg: '登录失败',
            code: 201
        },
    }
})

Mock.mock(/\/admin/, 'get', option => {
    return {
        meta: {
            msg: '获取数据成功',
            code: 200
        },
        role: roles[option.body]
    }
})
Mock.mock(/\/tabList/, 'get', () => {
    return {
        meta: {
            msg: '获取数据成功',
            code: 200
        },
        data: dataList
    }
})